<?php 
namespace app\common\model;
/**
 * @Author: YeMiao
 * @Date:   2017-07-31 11:23:52
 * @Last Modified by:   YeMiao
 * @Last Modified time: 2017-11-01 15:47:04
 */

use think\Model;
use app\common\model\AdminLog;
//
class AdminGroup extends Model{
	
	protected $resultSetType = 'collection';
	protected $createTime = false;
	protected $updateTime = false;

	// 获取全部数据
	public function get_list(){		
		$group = $this->select()->toArray();
		return $group;
	}
	// 添加数据
	public function add_group($data){
		try {
			$group = $this->insertGetId($data);	
		} catch (\Exception $e) {
			return 0;
		}
		$log = new AdminLog();
		$log->add_log('添加分组: 用户组:'.$data['group'].'别名:'.$data['name']);	
		return $group;
	}
	// 删除用户组
	public function del_group($data){
		$find = $this->get($data['id'])->toArray();
		$log = new AdminLog();
		$log->add_log('删除用户组:'.$find['group'].',别名:'.$find['name']);
		try {
			$group = $this->destroy($data);			
		} catch (\Exception $e) {
			return 0;
		}		
		return $group;
	}
	// 更新用户组别名
	public function update_name_group($data){
		$find = $this->get($data['id'])->toArray();
		$log = new AdminLog();
		$log->add_log('修改用户组:'.$find['group'].',别名"'.$find['name'].'"为"'.$data['name'].'"');
		try {
			$group = $this->save(['name' => $data['name']],['id' => $data['id']]);			
		} catch (\Exception $e) {
			$log->add_log('修改用户组:'.$find['group'].',别名"'.$find['name'].'"为"'.$data['name'].'",失败！');
			return 0;
		}
		return $group;		
	}
}

 ?>